<%@ page language="java" contentType="text/html; charset=gbk" pageEncoding="gbk"%>
<%@ page import="java.util.*" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.activiti.engine.ProcessEngine" %>
<%@ page import="org.activiti.engine.TaskService" %>
<%@ page import="org.activiti.engine.task.Task" %>
<%@ page import="org.activiti.engine.identity.User" %>
<%@ page import="org.activiti.engine.identity.Group" %>
<%@ page import="com.DateUtil" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<link type="text/css" rel="stylesheet" charset="utf-8" href="<%=request.getContextPath() %>/css/base.css"/>
<title>main</title>
</head>
<%
User user = (User)session.getAttribute("user");
List<String> groupIds = (List<String>)session.getAttribute("groupIds");
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);
TaskService taskService = (TaskService)context.getBean("taskService");

String doWhat = request.getParameter("doWhat");
if(doWhat != null && doWhat.equals("claim")){
	taskService.claim(request.getParameter("taskId"), user.getId());
}
List<Task> taskAssignee = taskService.createTaskQuery().taskAssignee(user.getId()).orderByTaskCreateTime().desc().list();
List<Task> taskCandidateGroups = taskService.createTaskQuery().taskCandidateGroupIn(groupIds).orderByTaskCreateTime().desc().list();
%>
<body>
<table align="center" width="100%">
	<caption>taskAssignee</caption> 
	<tr>
		<th align="center" scope="col">id</th>
		<th align="center" scope="col">name</th>
		<th align="center" scope="col">Assignee</th>
		<th align="center" scope="col">Description</th>
		<th align="center" scope="col">ProcessDefinitionId</th>
		<th align="center" scope="col">ProcessInstanceId</th>
		<th align="center" scope="col">TaskDefinitionKey</th>
		<th align="center" scope="col">CreateTime</th>
		<th align="center" scope="col">DelegationState</th>
		<th align="center" scope="col">DueDate</th>
		<th align="center" scope="col"></th>
	</tr>
	<%for(Task t : taskAssignee){%>
	<tr>
		<td class="row"><%=t.getId() %></td>
		<td class="row"><%=t.getName() %></td>
		<td class="row"><%=t.getAssignee() %></td>
		<td class="row"><%=t.getDescription() %></td>
		<td class="row"><%=t.getProcessDefinitionId() %></td>
		<td class="row"><%=t.getProcessInstanceId() %></td>
		<td class="row"><%=t.getTaskDefinitionKey() %></td>
		<td class="row"><%=DateUtil.format(t.getCreateTime(), "yyyy-MM-dd HH:mm") %></td>
		<td class="row"><%=t.getDelegationState() %></td>
		<td class="row"><%=DateUtil.format(t.getDueDate(), "yyyy-MM-dd HH:mm") %></td>
		<td class="row"><a href="<%=request.getContextPath() %>/jsp/handleTask.jsp?doWhat=handle&taskId=<%=t.getId() %>&processInstanceId=<%=t.getProcessInstanceId() %>&processDefinitionId=<%=t.getProcessDefinitionId() %>">handle</a></td>
	</tr>
	<%} %>
	<tr><td align="center" colspan="11" class="caption">taskCandidateGroups</td></tr>
	<tr>
		<th align="center" scope="col">id</th>
		<th align="center" scope="col">name</th>
		<th align="center" scope="col">Assignee</th>
		<th align="center" scope="col">Description</th>
		<th align="center" scope="col">ProcessDefinitionId</th>
		<th align="center" scope="col">ProcessInstanceId</th>
		<th align="center" scope="col">TaskDefinitionKey</th>
		<th align="center" scope="col">CreateTime</th>
		<th align="center" scope="col">DelegationState</th>
		<th align="center" scope="col">DueDate</th>
		<th align="center" scope="col"></th>
	</tr>
	<%for(Task t : taskCandidateGroups){%>
	<tr>
		<td class="row"><%=t.getId() %></td>
		<td class="row"><%=t.getName() %></td>
		<td class="row"><%=t.getAssignee() %></td>
		<td class="row"><%=t.getDescription() %></td>
		<td class="row"><%=t.getProcessDefinitionId() %></td>
		<td class="row"><%=t.getProcessInstanceId() %></td>
		<td class="row"><%=t.getTaskDefinitionKey() %></td>
		<td class="row"><%=DateUtil.format(t.getCreateTime(), "yyyy-MM-dd HH:mm") %></td>
		<td class="row"><%=t.getDelegationState() %></td>
		<td class="row"><%=DateUtil.format(t.getDueDate(), "yyyy-MM-dd HH:mm") %></td>
		<td class="row"><a href="<%=request.getContextPath() %>/jsp/main.jsp?doWhat=claim&taskId=<%=t.getId() %>">claim</a></td>
	</tr>
	<%} %>
</table>
</body>
</html>